package com.repository;

import com.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Set;

/**
 * @author Yadasu
 * @date 2020/12/21 16:59
 */
public interface RoleRepository  extends JpaRepository<Role,Integer> {

    @Query(value = "select * from sys_role where name=?1",nativeQuery = true)
    Role findByName(String name);

    /**
     * 根据用户ID查询
     * @param id 用户ID
     * @return /
     */
    @Query(value = "SELECT r.* FROM sys_role r, sys_user_role u WHERE " +
            "r.id = u.rid AND u.uid = ?1",nativeQuery = true)
    Set<Role> findByUserId(Long id);
}
